<%
Class IndexAction 'Extends CommonAction
    Sub index() 
      that.display ""
    end Sub  
    
    Sub insert()      
		dim db
		set db = M_("post").db	'可以直接定义到db
		
		' Create方法并不是添加数据，而是判断数据的合法性，自动调用model文件进行自动完成与自动验证。
        if db.Create(1) then	'1对应插入操作
			if M_("post").db.add() > 0 then	
				call that.success("添加成功")
			else
				call that.error("添加失败")
			end if
		else
			Call that.error( array(db.error,"",1) )
		end if
    end sub

      
    public sub read() 
		dim rs
		set rs = M_("post").db.field("post_id,content").select()  
		that.assign "msgs",rs
		that.display ""
		call that.u(rs)
    end sub 


    public sub del()
    	dim id
    	id = that.get("id")
    	if M_("post").db.where(id).remove() > 0 then
			call that.success("删除成功")
    	else
			call that.error("删除失败")
    	end if
	end sub
   

   public sub edit()
   		dim id,rs
   		id = that.get("id")

   		set rs = M_("post").db.field("post_id,content").where( that.get("id") ).find()

   		that.assign "rs",rs
		
		that.display ""   
		call that.u(rs)
   	end sub


   	public sub update()
		dim m
		set  m = M_("post")

		if not m.db.create(2) then	'2对应修改操作
			call that.error(m.db.error)
		end if
		
		'如果验证失败下面的代码不会执行到
	    if m.db.save()>0 then
			call that.success(array("修改成功！",U_("index/read"),3))
		else
			call that.error("修改失败")
		end if
   end sub
End Class
%>